// pages/list/list.js
var app=getApp();
var url = app.globalData.url;
var headers,next_page_token;
Page({
  data:{
    date: '2017-05-11',
    url:"https://app1.sztravel.com.cn/file/weixinapp/img",
    info:[],
    showLoading: true,//控制数据加载提示开关
    empty: false,//是否为空
  },
  request:function(flag){
    var that=this;
    var info=this.data.info;

    wx.request({
      url: url +'api/my_favor_list',
      header:headers,
      data:{
        next_page_token:next_page_token
      },
      success:function(data){//渲染收藏 翻页功能还没做 下周来了做
      console.log(data)
        console.log(data.data.data.favor_list);
        if(data.data.result===1){
          var empty=false
           if(flag){//判空
             info=[]
             if (!data.data.data.favor_list){
               empty=true
             }else{
               empty=false
             }
           }
          next_page_token = data.data.data.next_page_token;
          if (next_page_token){
            var showLoading=true;
          }else{
            var showLoading = false;
          }
          info.push.apply(info, data.data.data.favor_list);
          that.setData({
            info:info,
            empty:empty,
            showLoading: showLoading
          })
        }else{
          wx.showModal({
            title: "来自伴行的提示",
            content:data.data.message,
            showCancel: false,
            complete: function (res) {
            }
          })
        }
      }
    })
  },
  goToDetail:function(e){
    console.log(e)
    wx.navigateTo({
      url: '../line_detail/line_detail?lineId=' + e.currentTarget.dataset.id+'',
    })
  },
  onReachBottom: function () {
    // console.log("request")
    if (next_page_token) {
      this.request()
    };
  },
  onLoad:function(options){
    
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
    next_page_token = "";
    headers = app.globalData.headers;
    this.request(true)
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})